﻿using ReflectionStudio.Core.Events;
using System;
using System;
using System.ComponentModel;
using System.Data;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{ 
    public partial class UIFUNC:ViewBase
    {
        #region ==dwFN===========
        public static readonly DependencyProperty dwFNProperty = DependencyProperty.Register("dwFN",
            typeof(DataRow), typeof(UIFUNC),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwFNChanged));
        public DataRow dwFN
        {
            get
            {
                return (DataRow)GetValue(dwFNProperty);
            }
            set
            {
                SetValue(dwFNProperty, value);
            }
        }
        private static void OndwFNChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIFUNC;
            DataRow row = (DataRow)e.NewValue;
            if (src != null)
            {
                src.dwFN = row;
            }
        }
        #endregion
         
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwFN = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
            }
            else
            {
                KEY = dwMaster["FULLNAME"].ToString();
            }
        }
        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            VSDDAT.SD22.RESETSEQ("0022", "  ", "FNSEQ", 1);
            ((VICC_FUNCTIONS)MV).DeleteICC_FUNCTIONS(null, 0);
            foreach (DataRow _dwFUNC in TBMain.Rows)
            {
               
                _dwFUNC["ROWNID"] = VSDDAT.SD22.GETNEXT("0022", "  ", "FNSEQ", 1);
                ((VICC_FUNCTIONS)MV).InsertICC_FUNCTIONS(_dwFUNC, app.company);
            }
        }
    }
}
